package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.User;
import com.neusoft.po.Vip;
import com.neusoft.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/VipController")
public class VipController {
    @Autowired
    private VipService vipService;

    // 获取 VIP 等级，通过用户 ID（路径参数）
    @GetMapping("/getVipById/{userId}")
    public CommonResult getVipById(@PathVariable("userId") String userId) throws Exception {
        int vipLevel = vipService.getVipById(userId);
        return new CommonResult(200, "success", vipLevel);
    }

    // 保存 VIP 信息，通过用户 ID（请求体中传入 User）
    @PostMapping("/saveVip")
    public CommonResult saveVip(@RequestBody User user) throws Exception {
        int result = vipService.saveVip(user.getUserId());
        return new CommonResult(200, "success", result);
    }

    // 根据 VIP 信息获取优惠券数量
    @GetMapping("/getCouponById/{userId}/{vipId}")
    public CommonResult getCouponById(@PathVariable("userId") String userId, @PathVariable("vipId") String vipId) throws Exception {
        int couponCount = vipService.getCouponById(userId, vipId);
        return new CommonResult(200, "success", couponCount);
    }

    // 更新优惠券数量（请求体传入 Vip 对象）
    @PutMapping("/updateCouponQuantity")
    public CommonResult updateCuponQt(@RequestBody Vip vip) throws Exception {
        int result = vipService.updateCuponQt(vip);
        return new CommonResult(200, "success", result);
    }
}
